package stores

import (
	"JVM/Jvmgo/GoToJVM/instructions/base"
	"JVM/Jvmgo/GoToJVM/runtimeData"
)

/*
	这里写的存储指令: lstore，
	即将操作数栈顶的 long 型数据存入指定本地变量
*/

type LSTORE struct {
	base.Index8Instruction
}
type LSTORE_0 struct {
	base.NoOperandsInstruction
}
type LSTORE_1 struct {
	base.NoOperandsInstruction
}
type LSTORE_2 struct {
	base.NoOperandsInstruction
}
type LSTORE_3 struct {
	base.NoOperandsInstruction
}

func _lstore(frame *runtimeData.Frame, index uint) {
	val := frame.OperandStack().PopLong()
	frame.LocalVars().SetLong(index, val)
}

func (self LSTORE) Execute(frame *runtimeData.Frame) {
	_lstore(frame, uint(self.Index))
}
func (self LSTORE_0) Execute(frame *runtimeData.Frame) {
	_lstore(frame, 0)
}
func (self LSTORE_1) Execute(frame *runtimeData.Frame) {
	_lstore(frame, 1)
}
func (self LSTORE_2) Execute(frame *runtimeData.Frame) {
	_lstore(frame, 2)
}
func (self LSTORE_3) Execute(frame *runtimeData.Frame) {
	_lstore(frame, 3)
}
